<template>
  <div class="product-add pb50" v-loading="loading">
    <!--编辑文章-->
    <el-form size="small" :model="form" ref="form" label-width="100px">
      <div class="common-form">编辑提货码</div>
      <el-form-item label="所属卡券">
        {{ model.cardTitle }}
      </el-form-item>
      <el-form-item label="提货码">
        {{ model.codeNo }}
      </el-form-item>
      <el-form-item
        label="提货密码"
        :rules="[{ required: true, message: ' ' }]"
        prop="codePwd"
      >
        <el-input
          v-model="form.codePwd"
          placeholder=""
          class="max-w460"
        ></el-input>
      </el-form-item>
      <el-form-item
        label="提货时间"
        :rules="[{ required: true, message: ' ' }]"
        prop="startTime"
      >
        <el-date-picker
          v-model="form.startTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="选择开始时间"
        >
        </el-date-picker>
        <span>-</span>
        <el-date-picker
          v-model="form.endTime"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="选择结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="提货状态">
        <el-radio-group v-model="form.codeStatus">
          <el-radio :label="0">未提货</el-radio>
          <el-radio :label="1">已提货</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否作废">
        <el-radio-group v-model="form.isDelete">
          <el-radio :label="0">正常</el-radio>
          <el-radio :label="1">作废</el-radio>
        </el-radio-group>
      </el-form-item>
      <!--提交-->
      <div class="common-button-wrapper">
        <el-button
          size="small"
          type="info"
          @click="cancelFunc"
          :loading="loading"
          >取消</el-button
        >
        <el-button
          size="small"
          type="primary"
          @click="onSubmit"
          :loading="loading"
          >提交</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import CardApi from "@/api/card.js";
import { formatModel } from "@/utils/base.js";
export default {
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*form表单数据*/
      form: {
        codeId: 0,
        codePwd: "",
        startTime: "",
        endTime: "",
        codeStatus: "",
        isDelete: "",
      },
      /*新闻类别*/
      model: {},
    };
  },
  created() {
    this.getDetail();
  },

  methods: {
    getDetail() {
      let self = this;
      // 取到路由带过来的参数
      const params = self.$route.query.codeId;
      CardApi.toEditCode({ codeId: params }, true)
        .then((res) => {
          self.model = res.data;
          self.form = formatModel(self.form, res.data);
          self.loading = false;
        })
        .catch((error) => {});
    },

    /*修改文章*/
    onSubmit() {
      let self = this;
      let params = self.form;
      params.codeId = self.$route.query.codeId;
      // 取到路由带过来的参数
      CardApi.editCode(params, true)
        .then((data) => {
          ElMessage({
            message: data.msg,
            type: "success",
          });
          self.cancelFunc();
        })
        .catch((error) => {});
    },

    /*取消添加，返回文章列表*/
    cancelFunc() {
      this.$router.back(-1);
    },
  },
};
</script>

<style>
.edit_container {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

.ql-editor {
  height: 400px;
}
</style>
